const express = require('express')
const { readFileSync } = require("fs");
const { resolve } = require("path");
const router = express.Router()

const duration = JSON.parse(
    readFileSync(resolve(__dirname, "../../data/course/duration.json"), "utf8")
);
const course = JSON.parse(
    readFileSync(resolve(__dirname, "../../data/course/course.json"), "utf8")
);
const teacher = JSON.parse(
    readFileSync(resolve(__dirname, "../../data/course/teacher.json"), "utf8")
);

router.get("/initial_data", (req, res) => {
    const schedule = JSON.parse(
        readFileSync(resolve(__dirname, "../../data/course/schedule.json"), "utf8")
    );

    res.json({
        code: 200,
        msg: "ok",
        data: {
            duration,
            course,
            teacher,
            schedule,
        },
    });
});

module.exports = router